﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using Microsoft.VisualBasic;

using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace UdpReceive
{
    class Program
    {
        public struct Test //Structen för Divelistan
        {
            public string Id;
            public string Height;
            public string Dive;
        };

        public static string GetPublicIP()
        {
            String direction = "";
            WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
            using (WebResponse response = request.GetResponse())
            using (StreamReader stream = new StreamReader(response.GetResponseStream()))
            {
                direction = stream.ReadToEnd();
            }

            //Search for the ip in the html
            int first = direction.IndexOf("Address: ") + 9;
            int last = direction.LastIndexOf("</body>");
            direction = direction.Substring(first, last - first);

            return direction;
        }



        static void Main(string[] args)
        {

           

            ASCIIEncoding encode = new ASCIIEncoding();

            Console.WriteLine("Receiving PC\n");
            Console.WriteLine("Input ip of the other PC: ");
            string receivingIP = Console.ReadLine();

            UdpClient uC = new UdpClient(25001);

            IPAddress ipAddress = null;
            IPAddress.TryParse(receivingIP, out ipAddress);
            IPEndPoint rxPoint = new IPEndPoint(ipAddress, 25001);



            while (true)
            {

                byte[] b;
                b = uC.Receive(ref rxPoint);

                Console.WriteLine(encode.GetString(b));




            }
            Console.ReadKey();
        }
    }
}
